package com.mm.girl.controller;

import com.mm.girl.entity.ImageUrl;
import com.mm.girl.entity.Mp4Url;
import com.mm.girl.service.DataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author admin
 */
@CrossOrigin
@RestController
@RequestMapping("api")
@Api(value = "api接口")
@Slf4j
public class DataController {

    @Resource
    private DataService dataService;

    @ApiOperation(value = "获取MP4链接")
    @RequestMapping(value = "getMp4Url", method = {RequestMethod.POST})
    public Mp4Url getMp4Url(String source, HttpServletRequest request) {
        String uip = request.getRemoteAddr();
        log.info(uip);
        Mp4Url mp4Url = dataService.getMp4Url(source);
        mp4Url.setUip(uip);
        return mp4Url;
    }

    @ApiOperation(value = "获取图片链接", notes = "图片源：https://wallhaven.cc/")
    @RequestMapping(value = "getImageUrl", method = {RequestMethod.POST})
    public ImageUrl getImageUrl() {
        return dataService.getImageUrl();
    }
}
